package com.yenlien.traceyun.control.controller;

import com.yenlien.traceyun.control.entity.Goods;
import com.yenlien.traceyun.control.interceptor.UserAuthUtil;
import com.yenlien.traceyun.control.service.GoodsService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author jialong
 * @date 2021/05/18
 * @description: 仓库
 **/
@RestController
@RequestMapping("/goods")
public class GoodsController extends BaseController {

    @Autowired
    private GoodsService goodsService;


    @PostMapping(value = "/save")
    public Object save(@Validated @RequestBody Goods goods) {
        goods.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        return success(goodsService.save(goods));
    }

    @GetMapping(value = "/del")
    public Object del(Long goodsId) {
        goodsService.del(goodsId);
        return success("success");
    }

    @PostMapping(value = "/findList")
    public Object findByList(@Validated Goods goods) {
        return buildPage(goodsService.findList(goods));
    }


    @GetMapping(value = "/findById/{id}")
    public Object findById(@PathVariable Long id) {
        return success(goodsService.findById(id));
    }

    @GetMapping(value = "/findBySId/{id}")
    public Object findBySId(@PathVariable Long id) {
        return success(goodsService.findBySId(id));
    }


}
